<template>
  <div class="container">
    <IForm :formFrame="frame" labelWidth="200px" class="form-container" :formData.sync="form"></IForm>
    <div slot="action">
      <a-button class="btn" type="primary" @click="submit">保存</a-button>
    </div>
  </div>
</template>

<script>
  // import AttrEditor from "./components/AttrEditor"
  import IForm from "@/components/IForm"

  const resourceType = 'kapaishe_majia_robot'

  export default {
    components: {
      IForm
      // AttrEditor
    },
    data() {
      return {
        uuid: '',
        form: {
          banner: []
        },
        categoryList: []
      }
    },
    computed: {
      categoryOptions() {
        return this.categoryList.map(item => {
          return {
            title: item.title,
            value: item.id
          }
        })
      },
      frame() {
        return [
          {
            title: '马甲机器人开关',
            key: 'is_enabled',
            type: 'boolean',
            placeholder: '',
            newline: true,
            required: true,
          },
          {
            title: '每日购买抽数',
            key: 'buy_num_every_day',
            type: 'number',
            required: true,
            suffix: '抽',
            default: 800,
            newline: true,
          },
          {
            title: '最小任务间隔',
            key: 'min_interval',
            type: 'number',
            required: true,
            suffix: '秒',
            default: 20,
            newline: true,
          },
          {
            title: '最大任务间隔',
            key: 'max_interval',
            type: 'number',
            required: true,
            suffix: '秒',
            default: 180,
            newline: true,
          },
          {
            title: '马甲机器人用户列表',
            key: 'user_list',
            type: 'user_list_all_input',
            span: 24,
            placeholder: '请输入',
            newline: true,
            tips: '请选择马甲用户，否则不会执行购买'
          },
          {
            title: '卡牌社列表',
            key: 'list',
            type: 'activity_list_input',
            activity_type: 'kapaishe',
            span: 24,
            placeholder: '请输入',
            newline: true
          },
        ]
      }
    },
    created() {
      this.$http.get(`/setting/sys/${resourceType}`).then(res => {
        this.form = res.data.setting || {}
        // this.form.return_type = this.form.return_type || 'money'
      })
    },
    mounted() {},
    watch: {},
    methods: {
      cancel() {
        this.$router.back(-1)
      },
      submit() {
        this.$http.post(`/setting/sys/${resourceType}`, {
          setting: this.form
        }).then(res => {
          this.$message.success('保存成功')
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  .form-container {
    padding-bottom: 120px;
  }

  .container {
    .btn {
      margin-right: 30px;
    }
  }
</style>
